package com.fc.v2.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.v2.common.base.BaseService;
import com.fc.v2.common.support.ConvertUtil;
import com.fc.v2.mapper.auto.LecturerMapper;
import com.fc.v2.model.auto.Lecturer;
import com.fc.v2.model.auto.LecturerExample;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.util.SnowflakeIdWorker;
import com.fc.v2.util.StringUtils;

/**
 * 讲师表 LecturerService
 * @Title: LecturerService.java 
 * @Package com.fc.v2.service 
 * @author fuce_自动生成
 * @email ${email}
 * @date 2021-06-16 14:19:34  
 **/
@Service
public class LecturerService implements BaseService<Lecturer, LecturerExample>{
	@Autowired
	private LecturerMapper lecturerMapper;
	
      	   	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<Lecturer> list(Tablepar tablepar,Lecturer lecturer){
	        LecturerExample testExample=new LecturerExample();
			//搜索
			if(StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
	        	testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
	        }else {//大搜索
	        	testExample.createCriteria().andLikeQuery(lecturer);
	        }
			//表格排序
			//if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        //	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        //}else{
	        //	testExample.setOrderByClause("id ASC");
	        //}
	        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
	        List<Lecturer> list= lecturerMapper.selectByExample(testExample);
	        PageInfo<Lecturer> pageInfo = new PageInfo<Lecturer>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = ConvertUtil.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			LecturerExample example=new LecturerExample();
			example.createCriteria().andIdIn(stringB);
			return lecturerMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public Lecturer selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return lecturerMapper.selectByPrimaryKey(id1);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(Lecturer record) {
		return lecturerMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(Lecturer record) {
				
		record.setId(null);
		
				
		return lecturerMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Lecturer record, LecturerExample example) {
		
		return lecturerMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Lecturer record, LecturerExample example) {
		
		return lecturerMapper.updateByExample(record, example);
	}

	@Override
	public List<Lecturer> selectByExample(LecturerExample example) {
		
		return lecturerMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(LecturerExample example) {
		
		return lecturerMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(LecturerExample example) {
		
		return lecturerMapper.deleteByExample(example);
	}

	public PageInfo<Lecturer> getLecturerByMechanism(Tablepar tablepar,Integer mechanismId){
		PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
		return new PageInfo<>(lecturerMapper.getLecturerByMechanism(mechanismId));
	}

	public Lecturer getLecturerInfo(Integer mechanismId,Integer id) {
		return lecturerMapper.getLecturerInfo(mechanismId,id);

	}
}
